home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / daemons / ipServer / RCS / udp.c,v < prev    next >
Encoding:
Text File  |  1991-05-22  |  34.8 KB  |  1,484 lines

  1. head     1.16;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.16
  10. date     91.05.21.17.01.35;  author mottsmth;  state Exp;
  11. branches ;
  12. next     1.15;
  13.  
  14. 1.15
  15. date     90.01.03.15.46.17;  author nelson;  state Exp;
  16. branches ;
  17. next     1.14;
  18.  
  19. 1.14
  20. date     89.07.23.17.33.50;  author nelson;  state Exp;
  21. branches ;
  22. next     1.13;
  23.  
  24. 1.13
  25. date     89.06.02.13.59.56;  author brent;  state Exp;
  26. branches ;
  27. next     1.12;
  28.  
  29. 1.12
  30. date     89.06.02.13.54.17;  author brent;  state Exp;
  31. branches ;
  32. next     1.11;
  33.  
  34. 1.11
  35. date     89.06.02.13.50.16;  author brent;  state Exp;
  36. branches ;
  37. next     1.10;
  38.  
  39. 1.10
  40. date     89.03.23.09.53.13;  author brent;  state Exp;
  41. branches ;
  42. next     1.9;
  43.  
  44. 1.9
  45. date     89.02.21.10.14.16;  author brent;  state Exp;
  46. branches ;
  47. next     1.8;
  48.  
  49. 1.8
  50. date     89.02.10.09.00.02;  author mendel;  state Exp;
  51. branches ;
  52. next     1.7;
  53.  
  54. 1.7
  55. date     88.10.17.09.08.51;  author ouster;  state Exp;
  56. branches ;
  57. next     1.6;
  58.  
  59. 1.6
  60. date     88.09.15.09.32.47;  author mendel;  state Exp;
  61. branches ;
  62. next     1.5;
  63.  
  64. 1.5
  65. date     88.08.16.11.19.00;  author mendel;  state Exp;
  66. branches ;
  67. next     1.4;
  68.  
  69. 1.4
  70. date     88.06.26.12.16.33;  author mendel;  state Exp;
  71. branches ;
  72. next     1.3;
  73.  
  74. 1.3
  75. date     88.04.27.09.10.49;  author brent;  state Exp;
  76. branches ;
  77. next     1.2;
  78.  
  79. 1.2
  80. date     87.12.13.18.55.38;  author andrew;  state Exp;
  81. branches ;
  82. next     1.1;
  83.  
  84. 1.1
  85. date     87.12.12.21.31.46;  author andrew;  state Exp;
  86. branches ;
  87. next     ;
  88.  
  89.  
  90. desc
  91. @@
  92.  
  93.  
  94. 1.16
  95. log
  96. @Clear msg peek flag
  97. @
  98. text
  99. @/* 
  100.  * udp.c --
  101.  *
  102.  *    Routines to handle incoming and outgoing UDP packets
  103.  *    as well as UDP-dependent  routines that implement the 
  104.  *    semantics of the socket operations defined in sockOps.c.
  105.  *
  106.  *    The routines follow the User Datagram Protocol specification
  107.  *    in RFC 768 (Aug. 1980).
  108.  *
  109.  *    Based on 4.3 BSD code:
  110.  *    "@@(#)udp_usrreq.c  7.5 (Berkeley) 3/11/88"
  111.  *
  112.  * Copyright 1987 Regents of the University of California
  113.  * All rights reserved.
  114.  * Permission to use, copy, modify, and distribute this
  115.  * software and its documentation for any purpose and without
  116.  * fee is hereby granted, provided that the above copyright
  117.  * notice appear in all copies.  The University of California
  118.  * makes no representations about the suitability of this
  119.  * software for any purpose.  It is provided "as is" without
  120.  * express or implied warranty.
  121.  */
  122.  
  123. #ifndef lint
  124. static char rcsid[] = "$Header: /sprite/src/daemons/ipServer/RCS/udp.c,v 1.15 90/01/03 15:46:17 nelson Exp Locker: mottsmth $ SPRITE (Berkeley)";
  125. #endif not lint
  126.  
  127.  
  128. #include "sprite.h"
  129. #include "dev/net.h"
  130. #include "inet.h"
  131. #include "ipServer.h"
  132. #include "stat.h"
  133. #include "ip.h"
  134. #include "udp.h"
  135. #include "socket.h"
  136. #include "sockInt.h"
  137. #include "route.h"
  138.  
  139. #ifndef KERNEL
  140. #include <dev/pdev.h>
  141. #endif
  142.  
  143. static void        Input();
  144. static unsigned int     GetPort();
  145.  
  146.  
  147. /*
  148.  *----------------------------------------------------------------------
  149.  *
  150.  * UDP_Init --
  151.  *
  152.  *    Causes a handler to be called whenever UDP packets arrive.
  153.  *
  154.  * Results:
  155.  *    None.
  156.  *
  157.  * Side effects:
  158.  *    None.
  159.  *
  160.  *----------------------------------------------------------------------
  161.  */
  162.  
  163. void
  164. UDP_Init()
  165. {
  166.     IP_SetProtocolHandler(NET_IP_PROTOCOL_UDP, Input);
  167. }
  168.  
  169. /*
  170.  *----------------------------------------------------------------------
  171.  *
  172.  * Input --
  173.  *
  174.  *    This routine accepts IP datagrams and processes data for
  175.  *    this protocol.
  176.  *
  177.  * Results:
  178.  *    None.
  179.  *
  180.  * Side effects:
  181.  *    None.
  182.  *
  183.  *----------------------------------------------------------------------
  184.  */
  185.  
  186. /*ARGSUSED*/
  187. static void
  188. Input(netID, packetPtr)
  189.     Rte_NetID    netID;        /* ID of the network the packet arrived on. */
  190.     IPS_Packet    *packetPtr;    /* Packet descriptor. */
  191. {
  192.     register Net_UDPHeader    *udpPtr;
  193.     register Net_IPHeader    *ipPtr;
  194.     Sock_SharedInfo         *sockPtr;
  195.     unsigned            udpLen;
  196.  
  197.     stats.udp.recv.total++;
  198.  
  199.     ipPtr  = packetPtr->ipPtr;
  200.     udpPtr = (Net_UDPHeader *) ((Address) ipPtr + ipPtr->headerLen*4);
  201.  
  202.     udpLen = Net_NetToHostShort(udpPtr->len);
  203.     if (udpLen < sizeof(Net_UDPHeader)) {
  204.     stats.udp.recv.shortLen++;
  205.     free(packetPtr->base);
  206.     return;
  207.     }
  208.     packetPtr->data = ((Address)udpPtr) + sizeof(Net_UDPHeader);
  209.     packetPtr->dataLen = udpLen - sizeof(Net_UDPHeader);
  210.  
  211.     /*
  212.      * While debugging, drop packets from the rwho, sunrpc, and route daemons.
  213.      */
  214.     switch (Net_NetToHostShort(udpPtr->srcPort)) {
  215.     case 111:    /* sunrpc */
  216.     case 513:     /* rhwod */
  217.     case 520:    /* routed */
  218.         stats.udp.recv.daemon++;
  219.         if (ips_Debug) {
  220.         free(packetPtr->base);
  221.         return;
  222.         }
  223.         break;
  224.     }
  225.  
  226.     /*
  227.      * If the packet was sent with a checksum, the checksum will be
  228.      * non-zero.
  229.      */
  230.     if (udpPtr->checksum != 0) {
  231.     Net_IPPseudoHdr        pseudoHdr;
  232.     unsigned short        sum;
  233.  
  234.     /*
  235.      * The checksum is computed for the IP "pseudo-header" and
  236.      * the UDP header and data. When the UDP checksum was calculated,
  237.      * the checksum field in the header was set to zero. When we 
  238.      * recalculate the value, we don't zero the field so the computed 
  239.      * value should be zero if the packet didn't get garbled.
  240.      */
  241.     pseudoHdr.source    = (ipPtr->source);
  242.     pseudoHdr.dest        = (ipPtr->dest);
  243.     pseudoHdr.zero        = 0;
  244.     pseudoHdr.protocol    = ipPtr->protocol;
  245.     pseudoHdr.len        = udpPtr->len;
  246.  
  247.     if (udpLen & 1) {
  248.         ((Address)udpPtr)[udpLen] = 0;
  249.     }
  250.     sum = Net_InetChecksum2(udpLen, (Address)udpPtr, &pseudoHdr);
  251.  
  252.     if (sum != 0) {
  253.         if (ips_Debug) {
  254.         (void) fprintf(stderr, "UDP: checksum %x != 0\n", sum);
  255.         }
  256.  
  257.         stats.udp.recv.badChecksum++;
  258.         free(packetPtr->base);
  259.         return;
  260.     }
  261.     }
  262.     stats.udp.recv.dataLen += udpLen;
  263.  
  264.     if (ips_Debug) {
  265.     (void) fprintf(stderr, 
  266.         "UDP Input: %d bytes, <%x, %d> <-- <%x, %d>; checksum = %x\n",
  267.         udpLen, 
  268.         Net_NetToHostInt(ipPtr->dest), 
  269.         Net_NetToHostShort(udpPtr->destPort), 
  270.         Net_NetToHostInt(ipPtr->source), 
  271.         Net_NetToHostShort(udpPtr->srcPort), 
  272.         udpPtr->checksum);
  273.         
  274.         
  275.     }
  276.  
  277.     sockPtr = Sock_Match(UDP_PROTO_INDEX, ipPtr->dest, 
  278.             udpPtr->destPort, ipPtr->source, udpPtr->srcPort, TRUE);
  279.  
  280.  
  281.     if (sockPtr != (Sock_SharedInfo *) NULL) {
  282.     stats.udp.recv.accepted++;
  283.     stats.udp.recv.acceptLen += udpLen;
  284.     UDP_SocketInput(sockPtr, ipPtr->source, udpPtr->srcPort, packetPtr);
  285.     } else {
  286.     free(packetPtr->base);
  287.     }
  288. }
  289.  
  290.  
  291.  
  292. /*
  293.  *----------------------------------------------------------------------
  294.  *
  295.  * UDP_Output --
  296.  *
  297.  *    This routine formats a UDP packet and causes it to be
  298.  *    delivered using the IP protocol. The UDP header is formatted
  299.  *    and a checksum is computed.
  300.  *
  301.  * Results:
  302.  *    ?    - result from IP_Output.
  303.  *
  304.  * Side effects:
  305.  *    None.
  306.  *
  307.  *----------------------------------------------------------------------
  308.  */
  309.  
  310. ReturnStatus
  311. UDP_Output(localAddr, remoteAddr, packetPtr)
  312.     Net_InetSocketAddr    localAddr;    /* Local socket address. */
  313.     Net_InetSocketAddr    remoteAddr;    /* Address of remote host. */
  314.     register IPS_Packet *packetPtr;    /* Packet descriptor. */
  315. {
  316.     register Net_UDPHeader    *udpPtr;
  317.     Net_IPPseudoHdr        pseudoHdr;
  318.     short            len;
  319.  
  320.     /*
  321.      * If a local address hasn't been assigned yet, use the official
  322.      * address in the packet.
  323.      */
  324.     if (localAddr.address == Net_HostToNetInt(NET_INET_ANY_ADDR)) {
  325.     localAddr.address = Rte_GetOfficialAddr(FALSE);
  326.     }
  327.  
  328.     udpPtr = (Net_UDPHeader *) (packetPtr->data - sizeof(Net_UDPHeader));
  329.     packetPtr->hdr.udpPtr = udpPtr;
  330.     packetPtr->hdrLen = sizeof(Net_UDPHeader);
  331.  
  332.     /*
  333.      * Compute the checksum for the header and pseudo-header.
  334.      */
  335.     len = packetPtr->dataLen + sizeof(Net_UDPHeader);
  336.     pseudoHdr.source    = (localAddr.address);
  337.     pseudoHdr.dest    = (remoteAddr.address);
  338.     pseudoHdr.zero    = 0;
  339.     pseudoHdr.protocol    = NET_IP_PROTOCOL_UDP;
  340.     pseudoHdr.len    = Net_HostToNetShort(len);
  341.     udpPtr->len        = pseudoHdr.len;
  342.     udpPtr->srcPort    = (localAddr.port);
  343.     udpPtr->destPort    = (remoteAddr.port);
  344.     udpPtr->checksum    = 0;
  345.     udpPtr->checksum    = Net_InetChecksum2((int) len, (Address)udpPtr, 
  346.                     &pseudoHdr);
  347.     if (udpPtr->checksum == 0) {
  348.     udpPtr->checksum = 0xFFFF;
  349.     }
  350.  
  351.     IP_FormatPacket(NET_IP_PROTOCOL_UDP, NET_UDP_TTL, localAddr.address, 
  352.             remoteAddr.address, packetPtr);
  353.  
  354.     if (ips_Debug) {
  355.     (void) fprintf(stderr,
  356.     "UDP_Output: %d bytes, <%x, %d> --> <%x, %d>\n",
  357.         Net_NetToHostShort(pseudoHdr.len), 
  358.         Net_NetToHostInt(localAddr.address), 
  359.         Net_NetToHostShort(localAddr.port),
  360.         Net_NetToHostInt(remoteAddr.address), 
  361.         Net_NetToHostShort(remoteAddr.port));
  362.     }
  363.     stats.udp.send.total++;
  364.     stats.udp.send.dataLen += packetPtr->dataLen;
  365.  
  366.     (void) IP_Output(packetPtr, TRUE);
  367.  
  368.     return(SUCCESS);
  369. }
  370.  
  371.  
  372. /*
  373.  *----------------------------------------------------------------------
  374.  *
  375.  * UDP_SocketOpen --
  376.  *
  377.  *    Does UDP-specific actions for opening a new socket. A port is 
  378.  *    assigned in case the client never does bind or connect operations 
  379.  *    on the socket.
  380.  *
  381.  * Results:
  382.  *    SUCCESS        - always returned.
  383.  *
  384.  * Side effects:
  385.  *    The socket is made ready for sending and receiving UDP packets.
  386.  *
  387.  *----------------------------------------------------------------------
  388.  */
  389.  
  390. /*ARGSUSED*/
  391. ReturnStatus
  392. UDP_SocketOpen(sockPtr, userID)
  393.     Sock_SharedInfo    *sockPtr;    /* Socket to be opened. */
  394.     int            userID;        /* Client's user ID. Ignored. */
  395. {
  396.     sockPtr->local.port = GetPort(Net_HostToNetInt(NET_INET_ANY_ADDR));
  397.     sockPtr->state = READY;
  398.     Sock_BufAlloc(sockPtr, SOCK_RECV_BUF, UDP_MAX_DATAGRAM_SIZE);
  399.     Sock_BufAlloc(sockPtr, SOCK_SEND_BUF, UDP_MAX_DATAGRAM_SIZE);
  400.     return(SUCCESS);
  401. }
  402.  
  403.  
  404. /*
  405.  *----------------------------------------------------------------------
  406.  *
  407.  * UDP_SocketClose --
  408.  *
  409.  *    Removes data from the socket's read and write queues.
  410.  *
  411.  * Results:
  412.  *    SUCCESS        - always returned.
  413.  *
  414.  * Side effects:
  415.  *    Deallocates buffers in the read and write queues.
  416.  *
  417.  *----------------------------------------------------------------------
  418.  */
  419.  
  420. ReturnStatus
  421. UDP_SocketClose(sockPtr)
  422.     register Sock_SharedInfo    *sockPtr;    /* Socket to be closed. */
  423. {
  424.     Sock_BufRemove(sockPtr, SOCK_RECV_BUF, -1);
  425.     Sock_BufRemove(sockPtr, SOCK_SEND_BUF, -1);
  426.     return(SUCCESS);
  427. }
  428.  
  429.  
  430. /*
  431.  *----------------------------------------------------------------------
  432.  *
  433.  * UDP_ReadRequest --
  434.  *
  435.  *    Handle a read request from a client accessing the UDP pseudo-device.
  436.  *    This is an optimized handling of the request-response protocol and
  437.  *    the buffering structures associated with UDP.  Basically there is
  438.  *    just a list of packets associated with the socket, and we point
  439.  *    the kernel at the first one and then remove it.
  440.  *
  441.  *    This should be cleaned up so it isn't quite so pseudo-device
  442.  *    dependent - especially if UDP is moved into the kernel.
  443.  * Results:
  444.  *    None.
  445.  *
  446.  * Side effects:
  447.  *    Removes the first packet from the list.
  448.  *
  449.  *----------------------------------------------------------------------
  450.  */
  451. #ifndef KERNEL
  452. void
  453. UDP_ReadRequest(privPtr, requestPtr, streamID)
  454.     Sock_PrivInfo *privPtr;    /* Socket state */
  455.     Pdev_Request *requestPtr;    /* Pseudo-device request */
  456.     int streamID;        /* Request-response stream */
  457. {
  458.     Pdev_Reply    reply;
  459.     Sock_SharedInfo    *sharePtr = privPtr->sharePtr;
  460.     Sock_BufInfo    *bufInfoPtr;
  461.     Sock_BufDataInfo   *dataPtr = (Sock_BufDataInfo *)NULL;
  462.  
  463.     reply.replySize = 0;
  464.     reply.status = SUCCESS;
  465.     /*
  466.      * Error checking.
  467.      */
  468.     if (requestPtr->hdr.replySize < 0) {
  469.     reply.status = GEN_INVALID_ARG;
  470.     reply.replyBuf = (Address) NULL;
  471.     goto readReply;
  472.     }
  473.     if (sharePtr->error != SUCCESS) {
  474.     reply.status = sharePtr->error;
  475.     sharePtr->error = SUCCESS;
  476.     goto readReply;
  477.     }
  478.     if ((sharePtr->state != READY) &&
  479.     (sharePtr->state != CONNECTED)) {
  480.     reply.status = NET_BAD_OPERATION;
  481.     goto readReply;
  482.     }
  483.     if (privPtr->recvFlags & NET_OUT_OF_BAND) {
  484.     reply.status = NET_BAD_OPERATION;
  485.     goto readReply;
  486.     }
  487.     /*
  488.      * Take the first packet from the socket buffer.
  489.      */
  490.     bufInfoPtr = &sharePtr->recvBuf;
  491.     if (List_IsEmpty(&bufInfoPtr->links)) {
  492.     if (Sock_IsRecvStopped(sharePtr)) {
  493.         reply.status = SUCCESS;
  494.     } else {
  495.         reply.status = FS_WOULD_BLOCK;
  496.     }
  497.     goto readReply;
  498.     }
  499.     dataPtr = (Sock_BufDataInfo *)List_First(&bufInfoPtr->links);
  500.     /*
  501.      * Set up the reply to reference the packet directly.
  502.      */
  503.     reply.replyBuf = dataPtr->bufPtr;
  504.     if (requestPtr->hdr.replySize > dataPtr->len) {
  505.     reply.replySize = dataPtr->len;
  506.     } else {
  507.     reply.replySize = requestPtr->hdr.replySize;
  508.     }
  509.     /*
  510.      * Save the address for recvfrom() emulation
  511.      */
  512.     privPtr->recvFrom = dataPtr->address;
  513. readReply:
  514.     /*
  515.      * Reply to the client.  The kernel will copy the data from
  516.      * the packet to the clients buffer as part of the reply.
  517.      */
  518.     reply.selectBits = Sock_Select(privPtr, TRUE); 
  519.     if (ips_Debug) {
  520.     fprintf(stderr, "UDP_ReadRequest: %d bytes, select 0x%x, status 0x%x\n",
  521.         reply.replySize, reply.selectBits, reply.status);
  522.     }
  523.     PdevReply(streamID, &reply, "read");
  524.     if (dataPtr != (Sock_BufDataInfo *) NULL) {
  525.     /*
  526.      * Nuke the packet.
  527.      */
  528.     if ((privPtr->recvFlags & SOCK_BUF_PEEK) == 0) {
  529.         bufInfoPtr->size -= dataPtr->len;
  530.         List_Remove((List_Links *) dataPtr);
  531.         free(dataPtr->base);
  532.         free(dataPtr);
  533.     } else {
  534.         privPtr->recvFlags &= ~SOCK_BUF_PEEK;
  535.     }
  536.     }
  537. }
  538. #endif /* not KERNEL */
  539.  
  540.  
  541. /*
  542.  *----------------------------------------------------------------------
  543.  *
  544.  * UDP_SocketRead --
  545.  *
  546.  *    THIS HAS BEEN REPLACED BY UDP_ReadRequest
  547.  *
  548.  *    Supplies data to a client doing a read on a UDP socket.
  549.  *    Normally the packet data is  copied to the buffer. If the
  550.  *    packet is smaller than the buffer, no additional packets 
  551.  *    are read so the client will get a short read. If the buffer
  552.  *    is too small, the remaining data in the packet is not saved 
  553.  *    for the next read. Normally, the packet is removed from the
  554.  *    queue and the memory is deallocated once it is read. This
  555.  *    is not the case when the flag NET_PEEK is given.
  556.  *
  557.  * Results:
  558.  *    SUCCESS            - the data were copied to the buffer.
  559.  *    FS_WOULD_BLOCK        - nothing to read.
  560.  *    NET_BAD_OPERATION    - tried to read out-of-band data (not
  561.  *                  defined for this protocol).
  562.  *              
  563.  * Side effects:
  564.  *    The read queue is shortened.
  565.  *
  566.  *----------------------------------------------------------------------
  567.  */
  568.  
  569. ReturnStatus
  570. UDP_SocketRead(privPtr, bufSize, buffer, amountReadPtr)
  571.     Sock_PrivInfo    *privPtr;    /* Ptr to socket's per-process info. */
  572.     int        bufSize;        /* # of bytes in buffer. */
  573.     Address    buffer;            /* Place to put the data. */
  574.     int        *amountReadPtr;        /* # of bytes actually put in buffer. */
  575. {
  576.     ReturnStatus status;
  577.     Sock_SharedInfo    *sharePtr = privPtr->sharePtr;
  578.  
  579.     if ((sharePtr->state != READY) && (sharePtr->state != CONNECTED)) {
  580.     return(NET_BAD_OPERATION);
  581.     }
  582.  
  583.     if (privPtr->recvFlags & NET_OUT_OF_BAND) {
  584.     return(NET_BAD_OPERATION);
  585.     }
  586.  
  587.     status = Sock_BufFetch(sharePtr, privPtr->recvFlags, bufSize, buffer, 
  588.         amountReadPtr, &privPtr->recvFrom);
  589.  
  590.     /*
  591.      * Clear the recvFlags because they are only good for 1 read operation.
  592.      */
  593.     if (status == SUCCESS) {
  594.     privPtr->recvFlags = 0;
  595.     }
  596.  
  597.     return(status);
  598. }
  599.  
  600.  
  601. /*
  602.  *----------------------------------------------------------------------
  603.  *
  604.  * UDP_SocketInput --
  605.  *
  606.  *    This routine is called when a UDP packet arrives from the network.
  607.  *    The packet is appended to the socket's read queue and the client
  608.  *    is notified that there's data to be read.
  609.  *
  610.  * Results:
  611.  *    None.
  612.  *
  613.  * Side effects:
  614.  *    New data is added to the read queue. The waiting client is
  615.  *    woken up. The packet is freed if the buffer is full.
  616.  *
  617.  *----------------------------------------------------------------------
  618.  */
  619.  
  620. void
  621. UDP_SocketInput(sockPtr, srcAddr, srcPort, packetPtr)
  622.     Sock_SharedInfo    *sockPtr;    /* Socket that should get the data. */
  623.     Net_InetAddress    srcAddr;    /* IP address of sender. */
  624.     unsigned int    srcPort;    /* UDP port of sender. */
  625.     IPS_Packet        *packetPtr;    /* Packet descriptor. */
  626. {
  627.     Net_InetSocketAddr    sockAddr;
  628.     int            amtWritten;
  629.  
  630.     sockAddr.address = srcAddr;
  631.     sockAddr.port = srcPort;
  632.     if ((Sock_BufAppend(sockPtr, SOCK_RECV_BUF, TRUE, packetPtr->dataLen, 
  633.         packetPtr->data, packetPtr->base, &sockAddr, &amtWritten) 
  634.     == SUCCESS) && (amtWritten == packetPtr->dataLen)) {
  635.     Sock_NotifyWaiter(sockPtr, FS_READABLE);
  636.     } else {
  637.     free(packetPtr->base);
  638.     }
  639. }
  640.  
  641.  
  642. /*
  643.  *----------------------------------------------------------------------
  644.  *
  645.  * UDP_WriteRequest --
  646.  *
  647.  *    Handle a request to write a UDP datagram to the network.
  648.  *    (This replaces UDP_SocketWrite).
  649.  *
  650.  * Results:
  651.  *    SUCCESS            - the data were sent.
  652.  *    NET_BAD_OPERATION    - the send flags were not 0 (the flag
  653.  *                  values aren't valid for this operation).
  654.  *    ?            - status from UDP_Output.
  655.  *
  656.  * Side effects:
  657.  *    The data will be sent in a packet.
  658.  *
  659.  *----------------------------------------------------------------------
  660.  */
  661.  
  662. ReturnStatus
  663. UDP_WriteRequest(privPtr, procID, bufSize, buffer, amtWrittenPtr)
  664.     register Sock_PrivInfo    *privPtr;
  665.     Proc_PID procID;
  666.     int bufSize;
  667.     char *buffer;
  668.     int *amtWrittenPtr;
  669. {
  670.     register Sock_SharedInfo *sharePtr = privPtr->sharePtr;
  671.     register int headerLen;
  672.     IPS_Packet packet;
  673.  
  674.     *amtWrittenPtr = 0;
  675.     if (bufSize > UDP_MAX_DATAGRAM_SIZE) {
  676.     return(FS_BUFFER_TOO_BIG);
  677.     }
  678.     if ((sharePtr->state != READY) && (sharePtr->state != CONNECTED)) {
  679.     return(NET_BAD_OPERATION);
  680.     }
  681.     /*
  682.      * Do sendto() emulation.  IOC_NET_SEND_INFO may have been used
  683.      * to set the address to which to send this packet.  sendto cannot
  684.      * be used if the socket is connected.
  685.      */
  686.     if (privPtr->sendInfoValid) {
  687.     /*
  688.      * The send info flags are not valid for UDP sockets.
  689.      */
  690.     if (privPtr->sendInfo.flags != 0) {
  691.         return(NET_BAD_OPERATION);
  692.     }
  693.     privPtr->sendInfoValid = FALSE;
  694.     if (privPtr->sendInfo.addressValid) {
  695.         if (sharePtr->state == CONNECTED) {
  696.         return(NET_ALREADY_CONNECTED);
  697.         }
  698.         sharePtr->sentTo = privPtr->sendInfo.address.inet;
  699.             if (sharePtr->sentTo.address == 
  700.             Net_HostToNetInt(NET_INET_BROADCAST_ADDR) &&
  701.         !(sharePtr->options & NET_OPT_BROADCAST)) {
  702.         return(NET_BAD_OPERATION);
  703.         }
  704.     } else {
  705.         /*
  706.          * If the socket's not connected, we don't have a valid 
  707.          * destination address.
  708.          */
  709.         if (sharePtr->state != CONNECTED) {
  710.         return(NET_NOT_CONNECTED);
  711.         }
  712.         sharePtr->sentTo = sharePtr->remote;
  713.     }
  714.  
  715.     } else {
  716.     if (sharePtr->state != CONNECTED) {
  717.         return(NET_NOT_CONNECTED);
  718.     }
  719.     sharePtr->sentTo = sharePtr->remote;
  720.     }
  721.     /*
  722.      * Initialize packet referencing data in place.
  723.      */
  724.     headerLen = sizeof(Net_UDPHeader) + NET_IP_MAX_HDR_SIZE +
  725.             sizeof(IPS_PacketNetHdr);
  726.     packet.dataLen = bufSize;
  727.     packet.totalLen = bufSize + headerLen;
  728.     packet.data = buffer;
  729.     packet.base = packet.dbase = buffer - headerLen;
  730.  
  731.     *amtWrittenPtr = bufSize;
  732.     return(UDP_Output(sharePtr->local, sharePtr->sentTo, &packet));
  733. }
  734.  
  735.  
  736. /*
  737.  *----------------------------------------------------------------------
  738.  *
  739.  * UDP_SocketWrite --
  740.  *
  741.  *    Takes data from a write call by a client and causes the data
  742.  *    to be sent out on the network.
  743.  *
  744.  * Results:
  745.  *    SUCCESS            - the data were sent.
  746.  *    NET_BAD_OPERATION    - the send flags were not 0 (the flag
  747.  *                  values aren't valid for this operation).
  748.  *    ?            - status from UDP_Output.
  749.  *
  750.  * Side effects:
  751.  *    The data will be sent in a packet.
  752.  *
  753.  *----------------------------------------------------------------------
  754.  */
  755.  
  756. ReturnStatus
  757. UDP_SocketWrite(privPtr, packetPtr, amtWrittenPtr)
  758.     Sock_PrivInfo    *privPtr;
  759.     IPS_Packet    *packetPtr;        /* Packet containing data to be
  760.                      * sent on the network. */
  761.     int        *amtWrittenPtr;        /* # of bytes sent to the remote host.*/
  762. {
  763.     ReturnStatus    status;
  764.     Sock_SharedInfo    *sharePtr = privPtr->sharePtr;
  765.  
  766.     *amtWrittenPtr = 0;
  767.  
  768.     if (packetPtr->dataLen > 
  769.          Sock_BufSize(sharePtr, SOCK_SEND_BUF, SOCK_BUF_MAX_SIZE)) {
  770.     return(FS_BUFFER_TOO_BIG);
  771.     }
  772.  
  773.     if ((sharePtr->state != READY) && (sharePtr->state != CONNECTED)) {
  774.     return(NET_BAD_OPERATION);
  775.     }
  776.  
  777.  
  778.     if (privPtr->sendInfoValid) {
  779.     /*
  780.      * The send info flags are not valid for UDP sockets.
  781.      */
  782.     if (privPtr->sendInfo.flags != 0) {
  783.         return(NET_BAD_OPERATION);
  784.     }
  785.  
  786.     /*
  787.      * See if the client has given us an explicit address about
  788.      * where to send the packet. 
  789.      */
  790.  
  791.     privPtr->sendInfoValid = FALSE;
  792.     if (privPtr->sendInfo.addressValid) {
  793.         /*
  794.          * If the socket's connected, the user can't specify a different
  795.          * destination.
  796.          */
  797.         if (sharePtr->state == CONNECTED) {
  798.         return(NET_ALREADY_CONNECTED);
  799.         }
  800.         sharePtr->sentTo = privPtr->sendInfo.address.inet;
  801.  
  802.     } else {
  803.         /*
  804.          * If the socket's not connected, we don't have a valid 
  805.          * destination address.
  806.          */
  807.         if (sharePtr->state != CONNECTED) {
  808.         return(NET_NOT_CONNECTED);
  809.         }
  810.         sharePtr->sentTo = sharePtr->remote;
  811.     }
  812.  
  813.     } else {
  814.     if (sharePtr->state != CONNECTED) {
  815.         return(NET_NOT_CONNECTED);
  816.     }
  817.     sharePtr->sentTo = sharePtr->remote;
  818.     }
  819.  
  820.     status = UDP_Output(sharePtr->local, sharePtr->sentTo, packetPtr);
  821.     free(packetPtr->base);
  822.  
  823.     if (status == SUCCESS) {
  824.     *amtWrittenPtr = packetPtr->dataLen;
  825.     }
  826.     return(status);
  827. }
  828.  
  829.  
  830. /*
  831.  *----------------------------------------------------------------------
  832.  *
  833.  * UDP_SocketSelect --
  834.  *
  835.  *    Handles UDP-specific checks to see if a socket is ready for
  836.  *    reading. The socket is always writable.
  837.  *
  838.  * Results:
  839.  *    An or'd combination of FS_READBLE and FS_WRITABLE.
  840.  *
  841.  * Side effects:
  842.  *    None.
  843.  *
  844.  *----------------------------------------------------------------------
  845.  */
  846.  
  847. int
  848. UDP_SocketSelect(sockPtr)
  849.     Sock_SharedInfo *sockPtr;    /* Socket to check the readiness of. */
  850. {
  851.     int flags = FS_WRITABLE;
  852.  
  853.     /*
  854.      * The socket is readable only if there's data in the read queue.
  855.      */
  856.     if (Sock_BufSize(sockPtr, SOCK_RECV_BUF, SOCK_BUF_USED) > 0) {
  857.     flags |= FS_READABLE;
  858.     }
  859.     return(flags);
  860. }
  861.  
  862.  
  863. /*
  864.  *----------------------------------------------------------------------
  865.  *
  866.  * UDP_SocketBind --
  867.  *
  868.  *    Does UDP-specific stuff for assigning the local address of a socket.
  869.  *
  870.  * Results:
  871.  *    SUCCESS            - the operation was successful.
  872.  *    NET_ADDRESS_NOT_AVAIL    - the caller gave an address that doesn't
  873.  *                  correspond to this host.
  874.  *    NET_ADDRESS_IN_USE    - the given address is already in use.
  875.  *    GEN_NO_PERMISSION    - tried to bind a port that is reserved
  876.  *                  to the super-user.
  877.  *
  878.  * Side effects:
  879.  *    The local socket address for a socket is assigned.
  880.  *
  881.  *----------------------------------------------------------------------
  882.  */
  883.  
  884. ReturnStatus
  885. UDP_SocketBind(sockPtr, addrPtr, userID)
  886.     register Sock_SharedInfo *sockPtr;    /* Socket to be bound. */
  887.     Net_InetSocketAddr    *addrPtr;    /* Local address to assign to the 
  888.                      * socket. */
  889.     int        userID;            /* User ID of the process. */
  890. {
  891.     Net_InetSocketAddr    temp;
  892.     temp = *addrPtr;
  893.  
  894.     /*
  895.      * If a specific Inetnet address is given, make sure it is valid for
  896.      * this host (i.e. it is one of the addresses assigned to the host).
  897.      */
  898.     if (temp.address != Net_HostToNetInt(NET_INET_ANY_ADDR)) {
  899.     if (!Rte_ValidateAddress(temp.address)) {
  900.         return(NET_ADDRESS_NOT_AVAIL);
  901.     }
  902.     }
  903.  
  904.     if (temp.port == 0) {
  905.     temp.port = GetPort(temp.address);
  906.     } else {
  907.     Boolean wildcard;
  908.  
  909.     /*
  910.      * Make sure the given port is OK to use. If the port # is in
  911.      * the reserved range then make sure the user has super-user
  912.      * privileges. 
  913.      */
  914.  
  915.     if ((Net_NetToHostShort(temp.port) < INET_PRIV_PORTS) && 
  916.         (userID != PROC_SUPER_USER_ID)) {
  917.         return(GEN_NO_PERMISSION);
  918.     }
  919.  
  920.     /*
  921.      * Check for the uniqueness of the new local <address,port> tuple
  922.      * among all UDP sockets.  The REUSE_ADDR option specifies the
  923.      * strictness of the check.  If the option is not set, then the
  924.      * local tuple can't be used by us if any other UDP socket is
  925.      * using it.  A looser check is made if the option is set:  we can
  926.      * use the local tuple even if it is used by other sockets but
  927.      * only if their remote tuple is not the <NET_INET_ANY_ADDR,0>
  928.      * wildcard.
  929.      */
  930.  
  931.     if (Sock_IsOptionSet(sockPtr, NET_OPT_REUSE_ADDR)) {
  932.         wildcard = FALSE;
  933.     } else {
  934.         wildcard = TRUE;
  935.     }
  936.     if (Sock_Match(UDP_PROTO_INDEX, temp.address, temp.port,
  937.             Net_HostToNetInt(NET_INET_ANY_ADDR), 0, wildcard) !=
  938.                 (Sock_SharedInfo *) NULL) {
  939.  
  940.         return(NET_ADDRESS_IN_USE);
  941.     }
  942.     }
  943.  
  944.     sockPtr->local = temp;
  945.     sockPtr->state = READY;
  946.     return(SUCCESS);
  947. }
  948.  
  949.  
  950.  
  951. /*
  952.  *----------------------------------------------------------------------
  953.  *
  954.  * UDP_SocketConnect --
  955.  *
  956.  *    Assigns a remote host <address,port> pair to a socket. 
  957.  *    From now on, only packets from this remote host will be
  958.  *    accepted for this socket.
  959.  *
  960.  * Results:
  961.  *    SUCCESS            - the operation was successful.
  962.  *    NET_ADDRESS_NOT_AVAIL    - an invalid port was specified.
  963.  *    NET_ALREADY_CONNECTED    - the socket is already connected.
  964.  *    NET_ADDRESS_IN_USE    - the <local,remote> pair is already
  965.  *                   in use by another socket.
  966.  *    
  967.  *
  968.  * Side effects:
  969.  *    The remote socket address for a socket is assigned.
  970.  *    The local socket address may also be assigned.
  971.  *
  972.  *----------------------------------------------------------------------
  973.  */
  974.  
  975. /*ARGSUSED*/
  976. ReturnStatus
  977. UDP_SocketConnect(sockPtr, remoteAddrPtr, initialize)
  978.     register Sock_SharedInfo    *sockPtr;    /* Socket to be connected. */
  979.     Net_InetSocketAddr    *remoteAddrPtr;    /* Remote address to send and receive
  980.                      * datagrams from. */
  981.     Boolean        initialize;    /* Ignored. */
  982. {
  983.     Net_InetSocketAddr    remote;
  984.     remote = *remoteAddrPtr;
  985.  
  986.  
  987.     /*
  988.      * If the socket's already connected, disconnect it by zeroing 
  989.      * the remote <address,port> and removing all data in the recv queue.
  990.      */
  991.  
  992.     if (sockPtr->state == CONNECTED) {
  993.     sockPtr->remote.address    = Net_HostToNetInt(NET_INET_ANY_ADDR);
  994.     sockPtr->remote.port    = 0;
  995.     sockPtr->state        = READY;
  996.     Sock_BufRemove(sockPtr, SOCK_RECV_BUF, -1);
  997.     }
  998.  
  999.  
  1000.     /*
  1001.      * A valid remote port must be specified.
  1002.      */
  1003.     if (remote.port == 0) {
  1004.     return(NET_ADDRESS_NOT_AVAIL);
  1005.     }
  1006.  
  1007.     /*
  1008.      * If the wildcard address or the broadcast wildcard are given, then
  1009.      * use the official address (explicit or broadcast) for the server.
  1010.      */
  1011.  
  1012.     if (ips_Debug) {
  1013.     fprintf(stderr, "Socket_Connect: remote_addr before = %x\n",
  1014.             remote.address);
  1015.     }
  1016.     if (remote.address == Net_HostToNetInt(NET_INET_ANY_ADDR)) {
  1017.     remote.address = Rte_GetOfficialAddr(FALSE);
  1018.     } else if (remote.address == Net_HostToNetInt(NET_INET_BROADCAST_ADDR)) {
  1019.     remote.address = Rte_GetOfficialAddr(TRUE);
  1020.     }
  1021.     if (ips_Debug) {
  1022.     fprintf(stderr, "Socket_Connect: remote_addr after = %x\n",
  1023.             remote.address);
  1024.     }
  1025.  
  1026.     if (sockPtr->local.address == Net_HostToNetInt(NET_INET_ANY_ADDR)) {
  1027.     Net_InetAddress    localAddr;
  1028.  
  1029.     /*
  1030.      * The socket doesn't have a local address part yet so 
  1031.      * use the official address for this server. Make sure the
  1032.      * <local <address,port> and remote <address,port> tuple is
  1033.      * unique among all open UDP sockets.
  1034.      */
  1035.  
  1036.     localAddr = Rte_GetOfficialAddr(FALSE);
  1037.     if (Sock_Match(UDP_PROTO_INDEX, localAddr, 
  1038.         sockPtr->local.port, remote.address, remote.port, FALSE) !=
  1039.         (Sock_SharedInfo *) NULL) {
  1040.         return(NET_ADDRESS_IN_USE);
  1041.     }
  1042.  
  1043.     /*
  1044.      * The socket has a unique address tuple. 
  1045.      * If a local port has not been chosen yet, assign an unused value.
  1046.      */
  1047.  
  1048.     sockPtr->local.address = localAddr;
  1049.     if (sockPtr->local.port == 0) {
  1050.         sockPtr->local.port = GetPort(localAddr);
  1051.     }
  1052.     } else {
  1053.     /*
  1054.      * The socket has a valid local <address, port>. Make sure the
  1055.      * the <local, remote> tuple is unique among all open UDP sockets.
  1056.      */
  1057.  
  1058.     if (Sock_Match(UDP_PROTO_INDEX, sockPtr->local.address, 
  1059.         sockPtr->local.port, remote.address, remote.port, FALSE) !=
  1060.         (Sock_SharedInfo *) NULL) {
  1061.         return(NET_ADDRESS_IN_USE);
  1062.     }
  1063.     }
  1064.     sockPtr->remote    = remote;
  1065.     sockPtr->state    = CONNECTED;
  1066.  
  1067.     return(SUCCESS);
  1068. }
  1069.  
  1070.  
  1071. /*
  1072.  *----------------------------------------------------------------------
  1073.  *
  1074.  * UDP_SocketShutdown --
  1075.  *
  1076.  *    Called when the client will not send any more data on the socket.
  1077.  *
  1078.  * Results:
  1079.  *    None.
  1080.  *
  1081.  * Side effects:
  1082.  *    The socket is prevented from sending data.
  1083.  *
  1084.  *----------------------------------------------------------------------
  1085.  */
  1086.  
  1087. /*ARGSUSED*/
  1088. ReturnStatus
  1089. UDP_SocketShutdown(sockPtr, how)
  1090.     Sock_SharedInfo     *sockPtr;    /* Socket to be shutdown. */
  1091.     int        how;        /* Type of shutdown wanted. */
  1092. {
  1093.     Sock_StopSending(sockPtr);
  1094.     return(SUCCESS);
  1095. }
  1096.  
  1097.  
  1098. /*
  1099.  *----------------------------------------------------------------------
  1100.  *
  1101.  * GetPort --
  1102.  *
  1103.  *    Assign a port for a given address and make sure it doesn't 
  1104.  *    doesn't conflict with an existing socket's binding address.
  1105.  *
  1106.  * Results:
  1107.  *    A new port #.
  1108.  *
  1109.  * Side effects:
  1110.  *    The port value is incremented.
  1111.  *
  1112.  *----------------------------------------------------------------------
  1113.  */
  1114.  
  1115. static unsigned int
  1116. GetPort(localAddr)
  1117.     Net_InetAddress    localAddr;    /* Address to check for uniqueness. */
  1118. {
  1119.     static unsigned int port = INET_PRIV_PORTS;
  1120.  
  1121.     do {
  1122.     port++;
  1123.     if ((port < INET_PRIV_PORTS) || (port > INET_SERVER_PORTS)) {
  1124.         port = INET_PRIV_PORTS;
  1125.     }
  1126.     } while (Sock_Match(UDP_PROTO_INDEX, localAddr, Net_HostToNetShort(port), 
  1127.             Net_HostToNetInt(NET_INET_ANY_ADDR), 0, FALSE) !=
  1128.                 (Sock_SharedInfo *) NULL);
  1129.     return(Net_HostToNetShort(port));
  1130. }
  1131. @
  1132.  
  1133.  
  1134. 1.15
  1135. log
  1136. @Got UDP broadcast to work.
  1137. @
  1138. text
  1139. @d26 1
  1140. a26 1
  1141. static char rcsid[] = "$Header: /sprite/src/daemons/ipServer/RCS/udp.c,v 1.14 89/07/23 17:33:50 nelson Exp $ SPRITE (Berkeley)";
  1142. d435 2
  1143. @
  1144.  
  1145.  
  1146. 1.14
  1147. log
  1148. @Fixed bug in udp checksums and fixed up debugging info.
  1149. @
  1150. text
  1151. @d26 1
  1152. a26 1
  1153. static char rcsid[] = "$Header: udp.c,v 1.3 89/06/08 20:18:08 mnelson Exp $ SPRITE (Berkeley)";
  1154. d599 5
  1155. a603 1
  1156.  
  1157. d912 4
  1158. d920 4
  1159. @
  1160.  
  1161.  
  1162. 1.13
  1163. log
  1164. @Added stdio.h
  1165. @
  1166. text
  1167. @d26 1
  1168. a26 1
  1169. static char rcsid[] = "$Header: /sprite/src/daemons/ipServer/RCS/udp.c,v 1.12 89/06/02 13:54:17 brent Exp $ SPRITE (Berkeley)";
  1170. a30 1
  1171. #include "stdio.h"
  1172. d97 1
  1173. d104 2
  1174. a105 6
  1175.     udpPtr->len      = Net_NetToHostShort(udpPtr->len);
  1176. #ifdef notdef
  1177.     udpPtr->srcPort  = Net_NetToHostShort(udpPtr->srcPort);
  1178.     udpPtr->destPort = Net_NetToHostShort(udpPtr->destPort);
  1179. #endif
  1180.     if (udpPtr->len < sizeof(Net_UDPHeader)) {
  1181. d111 1
  1182. a111 1
  1183.     packetPtr->dataLen = udpPtr->len - sizeof(Net_UDPHeader);
  1184. d147 1
  1185. a147 1
  1186.     pseudoHdr.len        = Net_HostToNetShort(udpPtr->len);
  1187. d149 2
  1188. a150 2
  1189.     if (udpPtr->len & 1) {
  1190.         ((Address)udpPtr)[udpPtr->len] = 0;
  1191. d152 1
  1192. a152 1
  1193.     sum = Net_InetChecksum2((int)udpPtr->len, (Address)udpPtr, &pseudoHdr);
  1194. d164 1
  1195. a164 1
  1196.     stats.udp.recv.dataLen += udpPtr->len;
  1197. d169 8
  1198. a176 2
  1199.         udpPtr->len, ipPtr->dest, udpPtr->destPort, 
  1200.         ipPtr->source, udpPtr->srcPort, udpPtr->checksum);
  1201. d185 1
  1202. a185 1
  1203.     stats.udp.recv.acceptLen += udpPtr->len;
  1204. d259 5
  1205. a263 3
  1206.         pseudoHdr.len, 
  1207.         localAddr.address, localAddr.port,
  1208.         remoteAddr.address, remoteAddr.port);
  1209. @
  1210.  
  1211.  
  1212. 1.12
  1213. log
  1214. @Fixed include
  1215. @
  1216. text
  1217. @d26 1
  1218. a26 1
  1219. static char rcsid[] = "$Header: /sprite/src/daemons/ipServer/RCS/udp.c,v 1.11 89/06/02 13:50:16 brent Exp Locker: brent $ SPRITE (Berkeley)";
  1220. d31 1
  1221. @
  1222.  
  1223.  
  1224. 1.11
  1225. log
  1226. @Updated to new pseudo-device interface
  1227. @
  1228. text
  1229. @d26 1
  1230. a26 1
  1231. static char rcsid[] = "$Header: /sprite/src/daemons/ipServer/RCS/udp.c,v 1.10 89/03/23 09:53:13 brent Exp Locker: brent $ SPRITE (Berkeley)";
  1232. d42 1
  1233. a42 1
  1234. #include <dev/pdev.new.h>
  1235. @
  1236.  
  1237.  
  1238. 1.10
  1239. log
  1240. @Added #ifdef KERNEL
  1241. @
  1242. text
  1243. @d26 1
  1244. a26 1
  1245. static char rcsid[] = "$Header: /sprite/src/daemons/ipServer/RCS/udp.c,v 1.9 89/02/21 10:14:16 brent Exp Locker: brent $ SPRITE (Berkeley)";
  1246. d42 1
  1247. a42 1
  1248. #include <dev/pdev.h>
  1249. @
  1250.  
  1251.  
  1252. 1.9
  1253. log
  1254. @Added specialized UDP_ReadRequest and UDP_WriteRequest that
  1255. use the pseudo-device request buffer directly in order
  1256. to save malloc/copy costs.
  1257. @
  1258. text
  1259. @d26 1
  1260. a26 1
  1261. static char rcsid[] = "$Header: /sprite/src/daemons/ipServer/RCS/udp.c,v 1.8 89/02/10 09:00:02 mendel Exp $ SPRITE (Berkeley)";
  1262. d41 1
  1263. d43 1
  1264. a43 2
  1265.  
  1266. #include <stdio.h>
  1267. d348 1
  1268. a348 1
  1269.  
  1270. d433 1
  1271. a433 1
  1272.  
  1273. @
  1274.  
  1275.  
  1276. 1.8
  1277. log
  1278. @Changed UPD to not use queued output.
  1279. @
  1280. text
  1281. @d26 1
  1282. a26 1
  1283. static char rcsid[] = "$Header: /sprite/src/daemons/ipServer/RCS/udp.c,v 1.7 88/10/17 09:08:51 ouster Exp Locker: mendel $ SPRITE (Berkeley)";
  1284. d41 2
  1285. a70 1
  1286.  
  1287. d263 1
  1288. a263 2
  1289.     (void) IP_Output(packetPtr);
  1290.     free(packetPtr->base);
  1291. d295 2
  1292. a296 6
  1293.     /*
  1294.      * The buffer are set at this weird size (9000 bytes) to allow NFS to
  1295.      * send 8192 + header info datagrams.
  1296.      */
  1297.     Sock_BufAlloc(sockPtr, SOCK_RECV_BUF, 9000);
  1298.     Sock_BufAlloc(sockPtr, SOCK_SEND_BUF, 9000);
  1299. d330 109
  1300. d441 2
  1301. d540 90
  1302. d712 1
  1303. @
  1304.  
  1305.  
  1306. 1.7
  1307. log
  1308. @Changed not to return FS_WOULD_BLOCK on a write unless zero bytes
  1309. were transferred.
  1310. @
  1311. text
  1312. @d26 1
  1313. a26 1
  1314. static char rcsid[] = "$Header: udp.c,v 1.6 88/09/15 09:32:47 mendel Exp $ SPRITE (Berkeley)";
  1315. d262 3
  1316. a264 1
  1317.     IP_QueueOutput(packetPtr);
  1318. @
  1319.  
  1320.  
  1321. 1.6
  1322. log
  1323. @Added/removed byte swapping for SPUR.
  1324. @
  1325. text
  1326. @d26 1
  1327. a26 1
  1328. static char rcsid[] = "$Header: udp.c,v 1.5 88/08/16 11:19:00 mendel Exp $ SPRITE (Berkeley)";
  1329. d414 1
  1330. d418 3
  1331. a420 3
  1332.     if (Sock_BufAppend(sockPtr, SOCK_RECV_BUF, TRUE, packetPtr->dataLen, 
  1333.         packetPtr->data, packetPtr->base, &sockAddr, (int *)NULL) 
  1334.     == SUCCESS) {
  1335. @
  1336.  
  1337.  
  1338. 1.5
  1339. log
  1340. @Converted to use new libc.a
  1341. @
  1342. text
  1343. @d26 1
  1344. a26 1
  1345. static char rcsid[] = "$Header: udp.c,v 1.4 88/06/26 12:16:33 mendel Exp $ SPRITE (Berkeley)";
  1346. d103 1
  1347. d106 1
  1348. a106 1
  1349.  
  1350. d118 1
  1351. a118 1
  1352.     switch (udpPtr->srcPort) {
  1353. d145 2
  1354. a146 2
  1355.     pseudoHdr.source    = ipPtr->source;
  1356.     pseudoHdr.dest        = ipPtr->dest;
  1357. d149 1
  1358. a149 1
  1359.     pseudoHdr.len        = udpPtr->len;
  1360. d222 1
  1361. a222 1
  1362.     if (localAddr.address == NET_INET_ANY_ADDR) {
  1363. d234 2
  1364. a235 2
  1365.     pseudoHdr.source    = Net_HostToNetInt(localAddr.address);
  1366.     pseudoHdr.dest    = Net_HostToNetInt(remoteAddr.address);
  1367. d240 2
  1368. a241 2
  1369.     udpPtr->srcPort    = Net_HostToNetShort(localAddr.port);
  1370.     udpPtr->destPort    = Net_HostToNetShort(remoteAddr.port);
  1371. d291 1
  1372. a291 1
  1373.     sockPtr->local.port = GetPort(NET_INET_ANY_ADDR);
  1374. d588 1
  1375. a588 1
  1376.     if (temp.address != NET_INET_ANY_ADDR) {
  1377. d605 1
  1378. a605 1
  1379.     if ((temp.port < INET_PRIV_PORTS) && 
  1380. d627 2
  1381. a628 1
  1382.             NET_INET_ANY_ADDR, 0, wildcard) != (Sock_SharedInfo *) NULL) {
  1383. d683 1
  1384. a683 1
  1385.     sockPtr->remote.address    = NET_INET_ANY_ADDR;
  1386. d702 1
  1387. a702 1
  1388.     if (remote.address == NET_INET_ANY_ADDR) {
  1389. d704 1
  1390. a704 1
  1391.     } else if (remote.address == NET_INET_BROADCAST_ADDR) {
  1392. d708 1
  1393. a708 1
  1394.     if (sockPtr->local.address == NET_INET_ANY_ADDR) {
  1395. d808 4
  1396. a811 3
  1397.     } while (Sock_Match(UDP_PROTO_INDEX, localAddr, port, 
  1398.             NET_INET_ANY_ADDR, 0, FALSE) != (Sock_SharedInfo *) NULL);
  1399.     return(port);
  1400. @
  1401.  
  1402.  
  1403. 1.4
  1404. log
  1405. @Increased the sizeo of the maximum udp SOCK_RECV_BUF and SOCK_SEND_BUF to
  1406. allow 9000 byte packets for Sun's NFS.
  1407. @
  1408. text
  1409. @d26 1
  1410. a26 1
  1411. static char rcsid[] = "$Header: udp.c,v 1.3 88/04/27 09:10:49 brent Exp $ SPRITE (Berkeley)";
  1412. d41 1
  1413. a41 3
  1414. #include "io.h"
  1415. #include "fs.h"
  1416. #include "mem.h"
  1417. d108 1
  1418. a108 1
  1419.     Mem_Free(packetPtr->base);
  1420. d123 1
  1421. a123 1
  1422.         Mem_Free(packetPtr->base);
  1423. d157 1
  1424. a157 1
  1425.         Io_PrintStream(io_StdErr, "UDP: checksum %x != 0\n", sum);
  1426. d161 1
  1427. a161 1
  1428.         Mem_Free(packetPtr->base);
  1429. d168 1
  1430. a168 1
  1431.     Io_PrintStream(io_StdErr, 
  1432. d183 1
  1433. a183 1
  1434.     Mem_Free(packetPtr->base);
  1435. d252 1
  1436. a252 1
  1437.     Io_PrintStream(io_StdErr,
  1438. d421 1
  1439. a421 1
  1440.     Mem_Free(packetPtr->base);
  1441. @
  1442.  
  1443.  
  1444. 1.3
  1445. log
  1446. @New update with Jacobson enhancements
  1447. @
  1448. text
  1449. @d26 1
  1450. a26 1
  1451. static char rcsid[] = "$Header: udp.c,v 6.3 88/04/24 23:12:44 andrew Exp $ SPRITE (Berkeley)";
  1452. d294 6
  1453. a299 2
  1454.     Sock_BufAlloc(sockPtr, SOCK_RECV_BUF, 2*4096);
  1455.     Sock_BufAlloc(sockPtr, SOCK_SEND_BUF, 4096);
  1456. @
  1457.  
  1458.  
  1459. 1.2
  1460. log
  1461. @increased recv buffer size.
  1462. @
  1463. text
  1464. @d11 3
  1465. d26 1
  1466. a26 1
  1467. static char rcsid[] = "$Header: udp.c,v 1.1 87/12/12 21:31:46 andrew Exp $ SPRITE (Berkeley)";
  1468. d246 3
  1469. @
  1470.  
  1471.  
  1472. 1.1
  1473. log
  1474. @Initial revision
  1475. @
  1476. text
  1477. @d23 1
  1478. a23 1
  1479. static char rcsid[] = "$Header: udp.c,v 6.0 87/09/08 15:57:15 andrew Stable $ SPRITE (Berkeley)";
  1480. d288 1
  1481. a288 1
  1482.     Sock_BufAlloc(sockPtr, SOCK_RECV_BUF, 4096);
  1483. @
  1484.